import React from "react";
//引入改变加减状态的方法
import { plusAction, minusAction } from "./redux/actions";
//引入关联redux和组件的connect
import { connect } from "react-redux";

class Counter extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <div>
                <button onClick={() => {
                    this.props.plus();
                }}>+</button>
                <div>{this.props.count}</div>
                <button onClick={() => {
                    this.props.minus()
                }}>-</button>
            </div>
        );
    }
}
// 改变状态方法
function mapActionToProps(dispatch) {
    return {
        plus: () => { dispatch(plusAction()) },
        minus: () => { dispatch(minusAction()) }
    }
}
// 状态返回值
function mapStateToProps(rootReducer) {
    return {
        count: rootReducer.counterReducer.count
    }
}

export default connect(mapStateToProps, mapActionToProps)(Counter);
